<?php

 include dirname(__FILE__).'/deamon.php';

    $deamon=new deamon;
    $deamon->deamon();

$serv = new swoole_server("127.0.0.1", 9501);


//设置异步任务的工作进程数量
$serv->set(array('task_worker_num' =>16,'daemonize '=> 1,));

    

//监听数据接收事件
$serv->on('receive', function($serv, $fd, $from_id, $data) {
    //投递异步任务
    $task_id = $serv->task($data);//非阻塞
    echo "同步代码执行完成\n";
});


//处理异步任务
$serv->on('task', function ($serv, $task_id, $from_id, $data) {
    //返回任务执行的结果


   

    handleFun($data);

    $serv->finish("finish");
});


//处理异步任务的结果
$serv->on('finish', function ($serv, $task_id, $data) {
    echo "异步任务执行完成";
});


$serv->start();


function handleFun($data){
       
    //异步将数据发送给ccc.php
     $url="ccc.php";
     $postUrl = $url;
     $curlPost = $data;

     $ch = curl_init(); //初始化curl
     curl_setopt($ch, CURLOPT_URL, $postUrl); //抓取指定网页
     curl_setopt($ch, CURLOPT_HEADER, 0); //设置header
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //要求结果为字符串且输出到屏幕上
     curl_setopt($ch, CURLOPT_POST, 1); //post提交方式
     curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
     $status = curl_exec($ch); //运行curl
     curl_close($ch);


  

}